/** 表单信息 */
export const formMixin = {
	data() {
		return {
			addressInfo: { address_id: "" },
			classification: {
				"spec_item_name": '',
				"shop_price": '',
			},
			buyNum: 1, // 购买数量
			popupShow1653961165769: false, // 是否显示sku
		}
	},
	onLoad() { uni.removeStorageSync("CONFIRM_GOOD_INFO"); },
	methods: {
		/** 选择地址 */
		toSelectAddr() {
			uni.navigateTo({
				url: "/pages/yhq/address/address?iss=1",
				events: {
					remove: addr => {
						if (this.addressInfo.address_id == addr.address_id) {
							this.addressInfo = {};
							const info = uni.getStorageSync("CONFIRM_GOOD_INFO")
							uni.setStorageSync("CONFIRM_GOOD_INFO", { ...info, address_id: undefined });
							this.getGoodInfo();
						}
					},
					update: addr => {
						const info = uni.getStorageSync("CONFIRM_GOOD_INFO")
						uni.setStorageSync("CONFIRM_GOOD_INFO", { ...info, address_id: addr.address_id });
						this.getGoodInfo();
					},
				}
			})
		},
		/** 去添加地址 */
		toAddAddr() { uni.navigateTo({ url: "/pages/yhq/editAddress/editAddress" }) },
		/** 用户信息认证 */
		uiAuthen() {
			if (!uni.getStorageSync('USER_TOKEN')) {
				uni.navigateTo({ url: "/pages/tabBar/passwordLogin/passwordLogin" })
				return false;
			} else if (!this.classification.sku_id && this.goodData.is_open_sku == 1) {
				this.openSpec();
				return false;
			}
			// else if (!this.addressInfo.address_id) {
			// 	this.$msg("请选择收货地址")
			// 	this.popupShow1653961165769 = false;
			// 	this.popupShow1698314536945 = true;
			// 	return false;
			// }
			return true;
		},
		/** 加入购物车 */
		async addCard() {
			if (!this.uiAuthen()) return;
			try {
				const res = await this.$post('6551c656acea0', {
					goods_id: this.id,
					sku_id: this.classification.sku_id,
					num: this.buyNum,
				});
				this.$msg(res.msg || "成功");
				this.popupShow1653961165769 = false;
			} catch (e) { this.$msg(e?.msg || "失败") }
		},
		/** 去购买 */
		async toBuyGood() {
			// if (!this.uiAuthen()) return;
			if (!this.classification.spec_item_name) {
				this.openSpec();
			} else {
				this.popupShow1653961165769 = false;
				var goods_info = [{ goods_id: this.id, num: this.buyNum, sku_id: this.classification.sku_id }];
				var address_id = this.addressInfo.address_id;
				uni.setStorageSync("CONFIRM_SCORE_GOOD_INFO", { goods_info, address_id });
				uni.navigateTo({ url: "/pages/grzx/cartBillingScore/cartBillingScore" })
			}
			
		},
	}
}